<?php

namespace app\consultant_module\controller;

use \app\common\controller\Base;
use \think\Validate;

class Message extends Base
{
    /*
     * 添加咨询师的提醒信息
     */
    public function add_message()
    {
        $consultant_id = input("param.now_consultant");
        $staff_id = session("user_id");
        $last_date = trim(input("param.now_time"));
        $content = trim(input("param.content"));
        $now_name = input("param.now_name");
        $info = [
            'consultant_id' => $consultant_id
            , 'staff_id' => $staff_id
            , 'last_date' => $last_date
            , 'content' => $content
            , 'consultant_name' => $now_name
        ];
        $res = db('system_message')->insert($info);
        if ($res) {
            return json([
                'status' => 1,
                'msg' => "添加成功"
            ]);
        } else {
            return json([
                'status' => 0,
                'msg' => "添加失败(请注意时间是否已经有预约)"
            ]);
        }
    }

    /*
     * 获取咨询师的提醒信息
     */
    public function get_message()
    {
        if (session('permissionsgroup_id') == 4) {
            $message_future = db('system_message')->where(['status' => 1, 'staff_id' => session("user_id")])->order('last_date', "asc")->select();
            $message_old = db('system_message')->where(['status' => 0, 'staff_id' => session("user_id")])->order('last_date', "desc")->select();
        } else {
            $message_future = "";
            $message_old = "";
        }
        return json([
            'status' => 1
            , 'msg' => "获取成功"
            , 'message_future' => $message_future
            , 'message_old' => $message_old
        ]);
    }

    /*
     * 改变咨询师的信息状态
     */
    public function change_message_status()
    {
        $id = input("param.id");
        $res = db('system_message')->where('id', $id)
            ->update(['status' => "0"]);
        if ($res) {
            $status = 1;
            $msg = "改变成功";
        } else {
            $status = 0;
            $msg = "改变失败";
        }
        $return = [
            "status" => $status
            , "msg" => $msg
        ];
        return $return;
    }
}

?>